<template>
  <div class="container">
    <!-- 头部 -->
    <header v-if="headerList.albumDetailInfo">
      <div class="logo">
        <router-link to="/home" class="logo-icon">
          <img src="https://imagev2.xmcdn.com/storages/3777-audiofreehighqps/49/07/GMCoOSMH3Kb7AAAPQgH_va2X.png"
            alt="logo">
        </router-link>
        <a href="*" class="openApp">
          打开
        </a>
      </div>
      <div class="albumInfoWrapper">
        <img class="bgimg" :src="`https://imagev2.xmcdn.com/${headerList.albumDetailInfo.albumInfo.cover}`" alt="">
        <div class="bg">
          <div class="albumInfo">
            <div class="imgwrapper">
              <img class="album-cover" :src="`https://imagev2.xmcdn.com/${headerList.albumDetailInfo.albumInfo.cover}`"
                alt="">
              <img class="picAlbum"
                src="//s1.xmcdn.com/yx/ximalaya-mobile-resource/last/dist/images/listen_pic_album@3x_d18f4f7.png" alt="">
              <div class="play-count">
                <Headset style="width:15px; height: 15px; vertical-align: bottom;" />
                145.10万
              </div>
              <div class="vip" v-if="headerList.albumDetailInfo.albumInfo.isVipFirst">
                VIP
              </div>
            </div>
            <div class="infowrapper">
              <h1>{{ headerList.albumDetailInfo.albumInfo.title }}</h1>
              <a class="namewrapper">
                <img :src="`https://imagev2.xmcdn.com/${anchorInfo.userInfo.logo}`" alt="">
                {{ anchorInfo.userInfo.nickname }}
              </a>
              <p>已订阅3663人</p>
            </div>
          </div>
        </div>
      </div>
      <div class="stretch-box" ref="deleteHeight">
        <div v-html="headerList.albumRichInfo.richIntro"></div>
        <div class="mask" v-if="isShow">
          <CaretBottom @click="handlerIsShow"
            style="width:15px; height: 15px; color: #f86442; position: absolute; left: 176px; top: 115px;" />
        </div>
      </div>
      <div class="album-btn pulse-run">
        打开APP,完整收听
      </div>
    </header>
    <!-- 主体 -->
    <div class="content">
      <!-- 节目 -->
      <div class="list-view" v-if="listView.totalCount">
        <div class="list-view-header">
          节目({{ listView.totalCount }})
          <span>
            <Sort style="width:15px; height: 15px; vertical-align: bottom;" />
            切换顺序
          </span>
        </div>
        <ul class="list-view-body">
          <li v-for="item in listView.trackDetailInfos" :key="item.id">
            <a href="" class="ellipsis">
              <VideoPlay style="width:28px; height: 28px; vertical-align: middle; margin-right: 6px;" />
              {{ item.trackInfo.title }}
            </a>
            <Download style="width:20px; height: 20px;padding-top: 2px; color: #7e8c8d;" />
          </li>
        </ul>
        <div class="list-view-footer">
          <a href="">
            加载更多
            <ArrowDown style="width:15px; height: 15px; vertical-align: middle;" />
          </a>
        </div>
      </div>
      <!-- 主播信息 -->
      <div class="normal-box" v-if="anchorInfo.userInfo">
        <h2>主播信息</h2>
        <div class="anchor">
          <a href="#" class="avatar">
            <img :src="`https://imagev2.xmcdn.com/${anchorInfo.userInfo.logo}`" alt="">
            <div class="isVip" v-if="anchorInfo.userInfo.isVip">VIP</div>
          </a>
          <div class="anchor-content">
            <a href="#">
              <h4>{{ anchorInfo.userInfo.nickname }}</h4>
              <p class="info ellipsis">{{ anchorInfo.userInfo.personalSignature }}</p>
              <p class="fans-info">
                <User style="width:15px; height: 15px; vertical-align: bottom;" />
                {{ (anchorInfo.statCountInfo.followerCount / 10000).toFixed(2) }}万
              </p>
            </a>
          </div>
          <div class="init-code">
            <User style="width:24px; height: 24px; color: #f86442; vertical-align: middle; margin-left: 5px;" />
            <p>加关注</p>
          </div>
        </div>
        <div class="list-container">
          <a href="">
            <cardItem v-for="item in anchorAlbumsList.albumBriefDetailInfos" :key="item.id" :albumItem="item" type="anchorAlbumsList"></cardItem>
          </a>
        </div>
      </div>
      <!-- 用户评论 -->
      <div class="userComments">
        <div class="comment-title">
          用户评论
        </div>
        <div class="stretch-box1" ref="deleteHeight1">
          <div class="comment">
            <ul class="comment-content" ref="deleteCommentHeight">
              <li v-for="item in commentsList" :key="item.id">
                <div class="comment-list">
                  <span class="comment-avater">
                    <img
                    :src="`https://imagev2.xmcdn.com/${item.smallHeader}`"
                      alt="">
                  </span>
                  <div class="comment-box">
                    <span class="comment-nickname">{{ item.nickname }}</span>
                    <p>
                      {{ item.content }}
                    </p>
                    <div class="comment-bottom">
                      <a href="#">回复</a>
                      <div class="time">2023-12-23</div>
                      <div class="init-code">{{ item.likes }}</div>
                    </div>
                  </div>
                </div>
              </li>
            </ul>
          </div>
          <div v-if="isShowComments" class="mask mask-move">
            <CaretBottom @click="handlerIsShowComment" style="width:15px; height: 15px; color: #f86442; position: absolute; left: 166px; top: 115px;" />
          </div>
        </div>
        <a href="#" v-if="isShowComments" @click="handlerIsShowComment" class="comment-more">查看更多评论</a>
      </div>
      <!-- 相似剪辑 -->
      <div class="similar-editing">
        <div class="similar-editing-title">
          相似剪辑
        </div>
        <div class="similar-editing-list">
          <cardItem v-for="item in similarEditingList" :key="item.id" :albumItem="item" type="similarEditingList"></cardItem>
        </div>
        <div class="similar-editing-footer">
          <div class="btn">
            <Refresh style="width:15px; height: 15px; vertical-align: middle;" />
            换一批
          </div>
        </div>
      </div>
      <!-- 猜你喜欢 -->
      <div class="guess-like">
        <div class="guess-like-title">猜你喜欢</div>
        <div class="guess-like-list">
          <recommend :recommend="limitedFreeAlbum"></recommend>
        </div>
        <div class="guess-like-footer">
          <a href="#">查看更多&nbsp;&gt;</a>
        </div>
      </div>
    </div>
    <!-- 底部 -->
    <footer>
      <img class="background"
        src="https://imagev2.xmcdn.com/storages/2165-audiofreehighqps/52/6D/GKwRIDoF6Ml9AAESnAEaI6xF.png!magick=webp"
        alt="">
      <div class="footer-logo">
        <img src="https://imagev2.xmcdn.com/storages/72b6-audiofreehighqps/30/CE/GMCoOR8H3gffAAAQWAIAHhDF.png!magick=webp"
          alt="">
        <p>© 2014-2024 喜马拉雅 版权所有</p>
      </div>
    </footer>
    <!-- 固定 -->
    <div class="fiexd">
      <a href="" class="buy-album">购买已更新全集<span>￥11.6</span></a>
      <a href="" class="toVip">6元开会员&nbsp;免费听</a>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Headset, Sort, CaretBottom, VideoPlay, Download, ArrowDown, User, Refresh } from '@element-plus/icons-vue'
import cardItem from '../../components/card-item/index.vue'
import recommend from '../../components/recommend/index.vue'
import { reqGetRecommend } from '@/api/home'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { reqGetHeader, reqGetListView, reqAnchorInfo, reqAnchorAlbums, reqGetComments, reqGetSimilarEditing } from '@/api/detail'

const $route = useRoute()

const id = $route.query.id
/* 定义响应式数据 */
const isShow = ref(true)
const isShowComments = ref(true)

const deleteHeight = ref();
const deleteHeight1 = ref();
const deleteCommentHeight = ref();

const limitedFreeAlbum = ref([])
const headerList = ref<any>([])
const listView = ref<any>({});
//收集作者id
const anchorId = ref();
const anchorInfo = ref<any>({});
const anchorAlbumsList = ref<any>([]);
const commentsList = ref<any>([]);
//收集相似作品参数
const kw = ref<any>('');
const page = ref<any>(1);
const similarEditingList = ref<any>([]);

/* 事件的回调 */
function handlerIsShow() {
  isShow.value = false
  deleteHeight.value.style.height = 'auto'
}

function handlerIsShowComment() {
  isShowComments.value = false
  deleteHeight1.value.style.height = 'auto'
  deleteCommentHeight.value.style.height = 'auto'
}
/* 声明周期 */
onMounted(() => {
  getHeader(id);
  getListView(id);
  getRecommend();
  getComments(id);
})

/* 功能函数 */
/* 获取用户评论 */
async function getComments(id:any){
  try {
    const result = await reqGetComments(id);
    if(result.ret == 0){
      commentsList.value = result.data.comments
    }
    
  } catch (error) {
    
  }
}

/* 获取作者相关作品 */
async function getAnchorAlbums(anchorId:any){
  try {
    const result = await reqAnchorAlbums(anchorId);
    if (result.ret == 0) {
      anchorAlbumsList.value = result.data
    }
    
  } catch (error) {
    
  }
}

/* 获取作者信息 */
async function getAnchorInfo(anchorId: any) {
  try {
    const result = await reqAnchorInfo(anchorId);
    if (result.ret == 0) {
      anchorInfo.value = result.data
    }
  } catch (error) {

  }
}

/* 获取节目列表 */
async function getListView(id: any) {
  try {
    const result = await reqGetListView(id);
    if (result.ret == 0) {
      listView.value = result.data
    }
  } catch (error) {
    console.log(error);
  }
}

/* 获取猜你喜欢 */
async function getRecommend() {
  try {
    const result = await reqGetRecommend();
    if (result.code == 0) {
      limitedFreeAlbum.value = result.data.limitedFreeAlbum.limitedTimeFreeAlbums
      limitedFreeAlbum.value.splice(0, 6)
    }
  } catch (error) {
    console.log(error);
  }
}

/* 获取头部内容 */
async function getHeader(id: any) {
  try {
    const result = await reqGetHeader(id);
    if (result.ret == 0) {
      headerList.value = result.data
      anchorId.value = result.data.anchorId
      getAnchorInfo(anchorId.value);
      getAnchorAlbums(anchorId.value);

      kw.value = headerList.value.albumDetailInfo.albumInfo.title;
      getSimilarEditing(kw.value,page.value);
    }

  } catch (error) {
    console.log(error);
  }
}

/* 获取相似剪辑的数据 */
async function getSimilarEditing(kw:any,page:any){
  try {
    const result = await reqGetSimilarEditing(kw,page);
    similarEditingList.value = result.data.album.docs;
    
  } catch (error) {
    
  }
}

</script>

<style scoped>
a {
  text-decoration: none;
}

.container {
  width: 100%;
}

/****  头部 ****/
.logo {
  padding: 15px 15px 15px 10px;
  height: 30px;
  display: flex;
  justify-content: space-between;
  background-color: rgba(34, 35, 37, .8);
}

.logo-icon img {
  width: 100px;
  height: 29px;
}

.openApp {
  width: 60px;
  height: 30px;
  vertical-align: baseline;
  border-radius: 15px;
  text-align: center;
  font-weight: 400;
  background-color: #fa2800;
  text-decoration: none;
  color: #fff;
  line-height: 30px;
  font-size: 14px;
  padding: 0 5px;
}

/* 标题部分 */
.albumInfoWrapper {
  height: 118px;
  position: relative;
}

.bgimg {
  width: 99%;
  height: 100%;
}

.bg {
  position: absolute;
  padding: 30px 20px 20px;
  background-color: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(15px);
  top: 0;
  left: 0;
}

.albumInfo {
  width: 100%;
  height: 100%;
  display: flex;

}

.imgwrapper {
  height: 100%;
  margin-right: 10px;
  position: relative;
}

.album-cover {
  height: 95px;
  width: 95px;
  border-radius: 6px;
}

.picAlbum {
  width: 24px;
  height: 95px;
  position: absolute;
  left: 95px;
}

.play-count {
  width: 80px;
  height: 17px;
  font-size: 12px;
  padding: 4px 10px 4px 5px;
  color: #fff;
  background-image: linear-gradient(90deg, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0.25) 100%);
  font-weight: 700;
  position: absolute;
  bottom: 10px;
  left: 0;
}

.vip {
  width: 32px;
  height: 15px;
  padding-left: 4px;
  background-image: linear-gradient(112deg, #c68953 0, #e3b890 54%, #fbd4ac 100%);
  border-radius: 2px 0 100px 0;
  font-size: 10px;
  color: #fff;
  position: absolute;
  top: 0;
}

.infowrapper {
  width: 215px;
  margin-left: 15px;
}

.infowrapper h1 {
  font-weight: 500;
  font-size: 17px;
  color: #fff;
  line-height: 23px;

  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
}

.namewrapper {
  display: block;
  padding: 10px 0;
  color: rgba(255, 255, 255, .81);
  font-size: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .4);
}

.namewrapper img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  vertical-align: middle;
  padding-right: 6px;
}

.infowrapper p {
  font-size: 12px;
  color: #fff;
  margin-top: 10px;
}

/* 隐藏内容 */
.stretch-box {
  margin-top: 30px;
  padding: 10px;
  height: 150px;
  position: relative;
  overflow: hidden;
}

.stretch-box1 {
  margin-top: 30px;
  padding: 10px;
  height: 150px;
  position: relative;
  overflow: hidden;
}

/* .stretch-box img {
  width: 100%;
  height: 2058px;
} */

.mask {
  width: 100%;
  height: 150px;
  position: absolute;
  top: 20px;
  left: 0;
  background-image: linear-gradient(-180deg, rgba(255, 255, 255, 0) 0, rgba(255, 255, 255, 0.8) 34%, rgba(255, 255, 255, 0.95) 66%, #fff 100%);
}

.pulse-run {
  width: 235px;
  height: 40px;
  line-height: 40px;
  margin: 0 auto;
  border-radius: 100px;
  text-align: center;
  font-size: 15px;
  color: #fff;
  background-image: linear-gradient(-269deg, #ff8b70 2%, #f86442 99%);
  animation: pulse 0.4s linear 0s infinite alternate;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  100% {
    transform: scale(1.08);
  }
}

/****  内容 ****/

/* 节目 */
.list-view {
  padding: 15px 15px 0;
  justify-content: space-between;
}

.list-view-header {
  font-size: 18PX;
  font-weight: 700;
  color: #333;
  display: flex;
  justify-content: space-between;
}

.list-view-header span {
  font-size: 14px;
  color: #999;
  font-weight: 400;
}

.list-view-body li {
  display: flex;
  justify-content: space-between;
  height: 27px;
  padding: 12px 0;
  width: 100%;
  border-bottom: 1px solid rgba(200, 200, 200, .2);
}

.list-view-body li a {
  font-size: 16px;
  color: #7e8c8d;
}

.list-view-footer {
  width: 100%;
  text-align: center;
}

.list-view-footer a {
  width: 100%;
  font-size: 15px;
  color: #f86442;
  padding: 17px 0;
  font-weight: 700;
}

/* 主播信息 */
.normal-box {
  padding: 15px;
  margin: 10px 0;
}

.normal-box h2 {
  font-size: 18px;
  font-weight: 700;
  color: #333;
  margin-bottom: 15px;
}

.anchor {
  width: 100%;
  height: 66px;
  display: flex;
}

.anchor a {
  width: 54px;
  height: 54px;
  position: relative;
}

.anchor a img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.isVip {
  width: 27px;
  height: 16px;
  color: #fff;
  background-color: #f86442;
  font-size: 14px;
  text-align: center;
  border-radius: 10px;
  position: absolute;
  top: 44px;
  left: 14px;
}

.anchor-content {
  padding: 0 20px 0 10px;
  width: 225px;
}

.anchor-content a {
  width: 100%;
  color: #7e8c8d;
}

.anchor-content a h4 {
  font-size: 16px;
  margin-bottom: 2px;
  color: #333;
}

.anchor-content a .info {
  width: 100%;
  font-size: 12px;
  color: #999;
}

.anchor-content a .fans-info {
  padding-top: 4px;
  width: 100%;
  color: #bbb;
  font-size: 12px;
}

.init-code p {
  font-size: 12px;
  padding-top: 3px;
  color: #f86442;
  font-weight: 400;
}

.list-container {
  padding: 27px 10px 0 0;
}

.list-container a {
  display: flex;
  justify-content: space-between;
}

/* 用户评论 */
.userComments {
  padding: 15px;
  background: #fff;
}

.userComments .stretch-box1 {
  height: 300px;
}

.comment-title {
  margin-bottom: 20px;
  font-size: 18px;
  font-weight: 700;
  color: #333;
}

.comment-content{
  height: 200px;
  overflow: hidden;
}
.comment-content li {

  margin-bottom: 28px;
}

.comment-list {
  display: flex;
}

.comment-avater {
  width: 35px;
  height: 35px;
  margin-right: 9px;
}

.comment-avater img {
  width: 100%;
  height: 100%;
}

.comment-box {
  width: 300px;
}

.comment-box span {
  margin-bottom: 4px;
  color: #666;
  font-size: 14px;
}

.comment-box p {
  font-size: 14px;
  color: #333;
}

.comment-bottom {
  display: flex;
  margin-top: 8px;
}

.comment-bottom a {
  font-size: 12px;
  color: #666;
  margin-right: 5px;
}

.comment-bottom .time {
  width: 225px;
  font-size: 11px;
  color: #999;
}

.init-code {
  font-size: 12px;
  color: #666;
}

.mask-move {
  top: 125px;
}

.comment-more {
  width: 245px;
  margin: 0 auto;
  text-align: center;
  color: #fe7959;
  display: block;
  padding: 10px 0;
  font-size: 14px;
  position: relative;
  bottom: 50px;
}

/* 相似剪辑 */
.similar-editing {
  padding: 15px 15px 22px;
  margin-bottom: 10px;
}

.similar-editing-title {
  font-size: 18px;
  padding-bottom: 10px;
  font-weight: 700;
}

.similar-editing-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-bottom: 25px;
}

.similar-editing-footer {
  height: 42px;
  width: 100%;
}

.similar-editing-footer .btn {
  width: 56px;
  height: 16px;
  margin-top: 10px;
  margin-bottom: 2px;
  padding: 7px 10px;
  background-color: #f24821;
  color: #fff;
  font-size: 12px;
  border-radius: 14px;
  margin: 0 auto;
}

/* 猜你喜欢 */
.guess-like {
  padding: 15px;
}

.guess-like-title {
  font-size: 18px;
  color: #333;
  font-weight: 700;
}

.guess-like-footer {
  width: 100%;
}

.guess-like-footer a {
  display: block;
  margin: 10px auto;
  text-align: center;
  padding: 17px 0;
  font-size: 15px;
  font-weight: 700;
  color: #f86442;
}

/****  底部 ****/
footer {
  height: 180px;
  width: 100%;
  position: relative;
}

footer .background {
  height: 100%;
  width: 100%;
  margin-bottom: -5px;
}

.footer-logo {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  text-align: center;
}

.footer-logo img {
  margin-top: 45px;
  width: 102px;
  height: 36px;
}

.footer-logo p {
  font-size: 12px;
  line-height: 16px;
  color: gray;
  margin-top: 15px;
}

/* 固定 */
.fiexd {
  position: fixed;
  width: 100%;
  height: 60px;
  bottom: 0;
  display: flex;
  flex: 1;

}

.buy-album {
  width: 50%;
  box-sizing: border-box;
  padding: 10px;
  font-size: 14px;
  color: #333;
  background-color: #fff;
  text-align: center;
  line-height: 40px;
}

.buy-album span {
  font-size: 18px;
  color: red;
}

.toVip {
  width: 50%;
  box-sizing: border-box;
  padding: 10px;
  font-size: 15px;
  line-height: 40px;
  color: #9b7b55;
  text-align: center;
  background-image: linear-gradient(125deg, #ffdebe 0, #f3cba6 46%, #dca574 100%);
}
</style>